package com.ronghui.cash.controller;

import com.ronghui.cash.dto.AddressJson;
import com.ronghui.cash.service.AddressService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

@RestController
@RequestMapping("/address")
public class AddressControler extends BaseController{
	
	@Autowired
	private AddressService addressService;
	
	/*@ResponseBody
	@RequestMapping("/list")
	public Response queryAddressByParentId(@RequestParam Long parentId){
		
		if(parentId==null){
			return failure("参数不能空 ！");
		}
		List<Address> addressList= addressService.selectList(new EntityWrapper<Address>().eq("parent_id",parentId));
		
		return success(addressList);
	}
	
	@ResponseBody
	@RequestMapping("/entity")
	public Response queryAddressById(@RequestParam Long id){
		
		if(id==null){
			return failure("参数不能空！");
		}
		
		Address address= addressService.selectById(id);
		
		return success(address);
	}*/
	@RequestMapping("/adressJson")
	public List<AddressJson> adessJson(){
        long parentId1= 0L;
		List<AddressJson> addressJsonList1 = addressService.selectAddressJsonByParentId(parentId1);
		for(int i = 0;i<addressJsonList1.size();i++){
			AddressJson addressJson1 = addressJsonList1.get(i);
			long parentId2= addressJson1.getId();
			List<AddressJson> addressJsonList2 = addressService.selectAddressJsonByParentId(parentId2);
			addressJson1.setChild(addressJsonList2);
			for(int j = 0;j<addressJsonList2.size();j++){
				AddressJson addressJson2= addressJsonList2.get(j);
				long parentId3= addressJson2.getId();
				List<AddressJson> addressJsonList3 = addressService.selectAddressJsonByParentId(parentId3);
				addressJson2.setChild(addressJsonList3);
			}
		}
		/*CityList cityList = new CityList();
		cityList.setCitylist(addressJsonList1);*/

		return addressJsonList1;
	}

	/**
	 * 获取省/市/区
	 *//*
	@RequestMapping(value = "getAddressInfo")
	public Response getAddressInfo(String parentId) {
		return success(addressService.selectList(new EntityWrapper<Address>().eq("parent_id",parentId)));
	}*/

}
